using UnityEngine;
using UnityEngine.UIElements;

public class SwapLayer : MonoBehaviour
{
    public GameObject Layer1;
    public GameObject Layer2;
    public GameObject Player;
    public bool isLayer1 = true;

    private void Start() 
    {
        UIDocument uiDocument = GetComponent<UIDocument>();
        VisualElement root = uiDocument.rootVisualElement;
        Layer1.SetActive(true);
        Layer2.SetActive(false);
        Button buttonSwap = root.Q<Button>("ButtonSwap");
        buttonSwap.clicked += LayerChanger;
    }

    public void LayerChanger() 
    {
        if (Player != null && Player.transform.parent != null)
        {
            Player.transform.SetParent(null);
        }

        if (isLayer1 == true) 
        {
            Layer1.SetActive(false);
            Layer2.SetActive(true);
            isLayer1 = false;
        }
        else 
        {
            Layer1.SetActive(true);
            Layer2.SetActive(false);
            isLayer1 = true;
        }
    }
}